<?php
if (!isset($_SESSION)){
    session_start();
}
include_once('utilidades.php');
date_default_timezone_set('America/Argentina/Buenos_Aires');
/**
 * Proteccion Injeccion SQL
 */
if (!isset($_REQUEST)){
    foreach ($_REQUEST as  $key => $value){
        $_REQUEST[$key] = delChrEspecial($value);
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Conexion
 *
 * @author federico
 */
class Conexion {

    private $host;
    private $bd;
    private $usuario;
    private $clave;
    private $conexion;

    function __construct() {
        $doc = new DOMDocument();
        $doc->load($_SERVER['DOCUMENT_ROOT'].'/Comercial/conexion.xml');
    
        //$doc->load($_SERVER['DOCUMENT_ROOT'].'/config/conexion.xml');
        $vhost = $doc->getElementsByTagName('host');
        $vdbname = $doc->getElementsByTagName('dbname');
        $vuser = $doc->getElementsByTagName('user');
        $vport = $doc->getElementsByTagName('port');
        $vpass = $doc->getElementsByTagName('password');

        //        echo '<br>host: '.$vhost->item(0)->nodeValue;
        //        echo '<br>dbname: '.$vdbname->item(0)->nodeValue;

        $this->host = $vhost->item(0)->nodeValue;
        $this->port = $vport->item(0)->nodeValue;
        $this->bd = $vdbname->item(0)->nodeValue;
        $this->usuario = $vuser->item(0)->nodeValue;
        $this->clave = $vpass->item(0)->nodeValue;

        $this->conexion = pg_connect("host=".$this->host." port=".$this->port." dbname=".$this->bd." user=".$this->usuario." password=".$this->clave);
    }

    public function getConexion() {
        return $this->conexion;
    }

    public function setConexion($host, $dbname, $user, $password) {
        $this->conexion = pg_connect("host=".$localhost ."dbname=".$dbname ."user=".$user ."password=".$password);
    }

    public function retornar($pQ) {
        try {
            $result = pg_query($pQ);
        }catch (Exception $e){            
            echo $e->getTrace();
            return false;
        }
        pg_close($this->conexion);
        return $result;
    }
}

?>
